package cn.zzmx.config;


import cn.zzmx.convert.DateConvert;
import cn.zzmx.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.*;


@Configuration
public class WebMvcConfig implements WebMvcConfigurer {


    @Autowired
    private DateConvert converter;

    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 添加转换器
     * @param registry
     */
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(converter);
    }




    @Value("${pic.upload-path}")
    private String uploadPath;
    @Value("${pic.uploadResourcesHandler}")
    private String uploadResourcesHandler;

    /**
     * 绑定服务器和本地的路径
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(uploadResourcesHandler).addResourceLocations("file://"+uploadPath);
    }
}
